/*    */ package com.cr.framework.shiro.service;
/*    */ 
/*    */ import com.cr.common.core.domain.entity.SysUser;
/*    */ import com.cr.common.utils.MyDateUtils;
/*    */ import com.cr.common.utils.MessageUtils;
/*    */ import com.cr.common.utils.ServletUtils;
/*    */ import com.cr.common.utils.ShiroUtils;
/*    */ import com.cr.framework.manager.AsyncManager;
/*    */ import com.cr.framework.manager.factory.AsyncFactory;
/*    */ import com.cr.system.service.ISysUserService;
/*    */ import org.springframework.beans.factory.annotation.Autowired;
/*    */ import org.springframework.stereotype.Component;
/*    */ import org.springframework.util.StringUtils;
/*    */ 
/*    */ @Component
/*    */ public class SysRegisterService {
/*    */   @Autowired
/*    */   private ISysUserService userService;
/*    */   
/*    */   @Autowired
/*    */   private SysPasswordService passwordService;
/*    */   
/*    */   public String register(SysUser user) {
/* 37 */     String msg = "", loginName = user.getLoginName(), password = user.getPassword();
/* 39 */     if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute("captcha"))) {
/* 41 */       msg = "验证码错误";
/* 43 */     } else if (StringUtils.isEmpty(loginName)) {
/* 45 */       msg = "用户名不能为空";
/* 47 */     } else if (StringUtils.isEmpty(password)) {
/* 49 */       msg = "用户密码不能为空";
/* 51 */     } else if (password.length() < 5 || password
/* 52 */       .length() > 20) {
/* 54 */       msg = "密码长度必须在5到20个字符之间";
/* 56 */     } else if (loginName.length() < 2 || loginName
/* 57 */       .length() > 20) {
/* 59 */       msg = "账户长度必须在2到20个字符之间";
/* 61 */     } else if ("1".equals(this.userService.checkLoginNameUnique(loginName))) {
/* 63 */       msg = "保存用户'" + loginName + "'失败，注册账号已存在";
/*    */     } else {
/* 67 */       user.setPwdUpdateDate(MyDateUtils.getNowDate());
/* 68 */       user.setUserName(loginName);
/* 69 */       user.setSalt(ShiroUtils.randomSalt());
/* 70 */       user.setPassword(this.passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
/* 71 */       boolean regFlag = this.userService.registerUser(user);
/* 72 */       if (!regFlag) {
/* 74 */         msg = "注册失败,请联系系统管理人员";
/*    */       } else {
/* 78 */         AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, "Register", MessageUtils.message("user.register.success", new Object[0]), new Object[0]));
/*    */       } 
/*    */     } 
/* 81 */     return msg;
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\shiro\service\SysRegisterService.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */